{extend name="Index/index"}
{block name="main"}
    <!--个个栏目体  开始-->
    <div class="right-wrapper">
        <!--我的收藏-->
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li class="layui-this font20">我的评论</li>
                <li class="font20">我的回复</li>
            </ul>
            <div class="layui-tab-content">
                <!--我的评论-->
                <div class="layui-tab-item layui-show">
                    <div class="nav-show" style="display:block">
                        {if condition="$discuss == null"}
                        <div style="display:block" class="no-like">
                            <img src="static/personal/img/collection.png" width="700">
                            <p>
                                暂无评论，赶紧去评论吧!
                            </p>
                        </div>
                        {else /}
                        <ul class="like-list" >
                            {volist name="discuss" id="v"}
                            <li class="image">
                                    <p class="font15" style="color: black;">我的评论 : <span >{$v['content']}</span><span class="mtl20">{$v['time'] | date='y-m-d H:i:s',###}</span></p>
                                <a href="" target="_blank" class="img-link mt20">
                                    <img src="{$v['amage']}">
                                </a>
                                <div class="doc-items-wrapper">
                                    <div class="doc-items mt30" >
                                        <a href="" target="_blank">
                                            <h3>{$v['aname']}</h3>
                                        </a>
                                    </div>
                                </div>
                                <p>
                                    <span class="mtl480 answer" data-id="{$v['did']}" style="cursor: pointer;"> 回复 ( {$v['answer']}) </span>
                                    <span class="like-remove">删除评论
                                            <i data-id="{$v['did']}" >x</i>
                                    </span>
                                </p>
                            </li>
                            {/volist}
                        </ul>
                        {/if}
                    </div>
                </div>
                 <!--回复评论-->
                <div class="layui-tab-item">
                    <div class="nav-show" style="display:block">
                        {if condition="$answer == null"}
                        <div style="display:block" class="no-like">
                            <img src="static/personal/img/collection.png" width="700">
                            <p>
                                暂无回复，赶紧去评论吧!
                            </p>
                        </div>
                        {else /}

                        <ul class="like-list" >
                            {volist name="answer" id="v"}
                            <li class="image">

                                <p class="font15" style="color: black;">我的回复 : <span >{$v['contente']}</span><span class="mtl20">{$v['times'] | date='y-m-d H:i:s',###}</span></p>
                                <p class="font15 mt20" style="color: black;">{$v['nickname']}的评论 : <span class=" font15">{$v['content']}</span></p>
                                <a href="" target="_blank" class="img-link">
                                    <img src="{$v['amage']}">
                                </a>
                                <div class="doc-items-wrapper">
                                    <div class="doc-items mt30" >
                                        <a href="" target="_blank">
                                            <h3>{$v['aname']}</h3>
                                        </a>
                                    </div>
                                </div>
                                <p>
                                    <span class="mtl480 answer" data-id="{$v['did']}" style="cursor: pointer;"> 回复</span>
                                    <span class="ansers">删除回复
                                            <i data-id="{$v['id']}" >x</i>
                                    </span>
                                </p>
                            </li>
                            {/volist}
                        </ul>
                        {/if}
                    </div>


                </div>
            </div>
        </div>
    </div> <!--个个栏目体 结束-->
</div>  <!--main 结束-->
{js href="/static/home/js/jquery.min.js" /}
{js href="/static/home/js/bootstrap.js" /}
{js href="/static/personal/layui/layui.js"}
<script>
    $(function () {
        $('.like-remove').bind('click', function () {
            var id = $(this).children('i').attr('data-id');
            var _this = this;
            $.ajax({
                type: 'get',
                url: 'discuss/'+id,
                dateType: 'json',
                success: function (data) {
//                    console.log(_this);
                    if (data > 0){
                        $(_this).parents('li').remove();
                    } else {
                        alert('取消评论失败');
                    }
                },
                error: function () {
                    // AJAX执行失败
                    alert('ajax操作失败');
                }
            });
        });


        $('.ansers').bind('click', function () {
            var id = $(this).children('i').attr('data-id');
            var _this = this;
            $.ajax({
                type: 'get',
                url: 'discuss/del/'+id,
                dateType: 'json',
                success: function (data) {
//                    console.log(_this);
                    if (data > 0){
                        $(_this).parents('li').remove();
                    } else {
                        alert('取消回复失败');
                    }
                },
                error: function () {
                    // AJAX执行失败
                    alert('ajax操作失败');
                }
            });
        });
    });


    layui.use(['form','layer','element'],function(){
        var form = layui.form();
        var $ = layui.jquery, layer = layui.layer;
        $('.answer').on('click',function(){
            var id = $(this).attr('data-id');
            demo(id);
            layer.open({
                type: 1,
                title:'回复评论',
                skin: 'layui-layer-rim', //加上边框
                area: ['400px', '400px'], //宽高
                content:'<div class="anser"></div><br><form action="discuss/update" method="post" enctype="multipart/form-data">回复 : <input type="text" name="content"><br><input type="hidden" name="did" value="'+ id +'"><input type="submit" class="layui-btn layui-btn-small mgl250"><br></form>',
            });
        });

    });
    function demo(id) {
        $.ajax({
            type:'get',
            url:'discuss/read/'+id,
            dateType:'json',
            success:function(data){

                for (var i = 0; i < data.length; i++){
                    $('<div class="layui-bg-gray mt10 font15 p5"><p><span class="datar">'+data[i]['nickname'] + '</span> : '+data[i]['contente']+'</p><p class="mgl250">'+getLocalTime(data[i]['times'])+'</p></div>').appendTo('.anser');
                }
            },
            error:function () {
                alert('ajax 加载失败....');
            }
        });
    }
    function getLocalTime(nS) {
        return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
    }

</script>

{/block}